/**
This definition is used to talk to the ModuleManager Service.
Other Services register their name and where they can be located.
Modules then query this ModuleManager for a certain name, and it returns the TCP address and port where it can be located
*/
namespace java hydrap2p.servicemanager
namespace py hydrap2p.servicemanager
namespace csharp hydrap2p.servicemanager

include "service.thrift"

service ServiceListener extends service.Service{
	/**
		Called when a service location is lost
	*/
	void delService(1:string name),
	
	/**
		Called when a new service location is set
	*/
	void newService(1:string name, 2:service.ServiceLocation location),
}

/**
This exception is thrown if a second service tries to register a name that is already taken
It returns what name were taken, and the location of the service that claimed it previously
*/
exception NameTaken {
	1: string name,
	2: service.ServiceLocation location,
}

service ServiceManager extends service.Service{
	/**
		Stores the location of a certain service, so that it may be found by its name later
	*/
	void setServiceLocation(1:string name, 2:service.ServiceLocation location) throws (1:NameTaken ouch),
	
	/**
		Returns the location for a given well-known name
		Returns null if that name is not known
	*/
	service.ServiceLocation getServiceLocation(1:string name),
	
	/**
		Returns the location for all known services
		Returns an empty map is there are no services
	*/
	map<string,service.ServiceLocation> getAllServiceLocations(),
	
	/**
		Delete the location of a named service
	*/
	void delServiceLocation(1:string name),
	
	/**
		Subscribes this given service to be notified of any changes in Services
		Returns true if it worked
	*/
	bool subscribe(1:service.ServiceLocation listener),
	
	/**
		Unsubscribes this given service from being notified of any changes in Services
	*/
	void unsubscribe(1:service.ServiceLocation listener),
	
}